﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MapLibrary.Players.Skills;
using FarseerPhysics.Dynamics;
using GUILibrary;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace MapLibrary.GUI
{
    /// <summary>
    /// This represents the component of the skill upgrade gui
    /// that allows for the upgrading of an individual skill.
    /// </summary>
    class SkillUpgradePanel
    {
        /// <summary>
        /// Width and Height of the Panel.  Public so GUI can
        /// place them correctly on the screen according to their
        /// width and height.
        /// </summary>
        public const int PANEL_WIDTH = 100;
        public const int PANEL_HEIGHT = 100;

        private const int BAR_PADDING = 10;
        private Vector2 ICON_PADDING = new Vector2(20, 20);
        private Vector2 ICON_DIM = new Vector2(50, 50);
        private const string AssetDirectory = "./GUIAssets/";

        /// <summary>
        /// Variables needed to load as content
        /// </summary>
        private Backdrop backDrop;
        private Backdrop icon;
        Button[] bars;

        private SkillData skillData;
        private GameWorld world;
        private String skillName;
        private Vector2 Position;

        public SkillUpgradePanel(GameWorld world, Vector2 Position, string skillName)
        {
            this.skillName = skillName;
            this.world = world;
            this.Position = Position;

            this.skillData = world.PlayerData.GetSkillDataByName(skillName);

            this.backDrop = new Backdrop();
            this.backDrop.TextureName = AssetDirectory + skillName + "/Backdrop";
            this.backDrop.Position = this.Position;

            this.icon = new Backdrop();
            this.icon.TextureName = AssetDirectory + skillName + "/Icon";
            this.icon.Position = this.Position + ICON_PADDING;

            bars = new Button[3];

            Vector2 paddingVect = new Vector2(0, BAR_PADDING);
            Vector2 buttonPos = this.Position + paddingVect + ICON_PADDING + new Vector2(ICON_DIM.X,0);
            for (int i = 0; i < 3; i++)
            {
                bars[i] = new ProteinBarButton(i, skillData);
                bars[i].Position = buttonPos;
                
                //possibly set action here.

                buttonPos += paddingVect;
            }
        }

        /// <summary>
        /// Load the SkillUpgradePanel components.
        /// </summary>
        /// <param name="manager"></param>
        public void Load(ContentManager manager)
        {
            icon.load(manager);
            backDrop.load(manager);

            for (int i = 0; i < 3; i++)
            {
                bars[i].load(manager);
            }
        }

        /// <summary>
        /// Adds the SkillUpgradePanel to the provided screen.  This involves placing
        /// the buttons into the button list, and placing the backdrops into the backdrop
        /// list.
        /// </summary>
        /// <param name="screen"></param>
        public void RegisterToScreen(GUIScreen screen)
        {
            for (int i = 0; i < 3; i++)
            {
                screen.Buttons.Add(bars[i]);
            }

            screen.Backdrops.Add(backDrop);
            screen.Backdrops.Add(icon);
        }

    }
}
